<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>使用Homebrew安装Redis | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="使用Homebrew安装Redis1、没有安装Homebrew，首先安装npm国内的吧，快一些。 打开终端输入以下命令： 1&#x2F;bin&#x2F;zsh -c &quot;$(curl -fsSL https:&#x2F;&#x2F;gitee.com&#x2F;cunkai&#x2F;HomebrewCN&#x2F;raw&#x2F;master&#x2F;Homebrew.sh)&quot;  2、使用Homebrew安装命令 1brew install redis   执">
<meta property="og:type" content="article">
<meta property="og:title" content="使用Homebrew安装Redis">
<meta property="og:url" content="https://lummer.gitee.io/hexo/2021/03/02/Mac%E5%AE%89%E8%A3%85Redis%EF%BC%8C%E5%8E%9F%E6%9D%A5%E5%B0%B1%E6%98%AF%E8%BF%99%E4%B9%88%E7%AE%80%E5%8D%95/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="使用Homebrew安装Redis1、没有安装Homebrew，首先安装npm国内的吧，快一些。 打开终端输入以下命令： 1&#x2F;bin&#x2F;zsh -c &quot;$(curl -fsSL https:&#x2F;&#x2F;gitee.com&#x2F;cunkai&#x2F;HomebrewCN&#x2F;raw&#x2F;master&#x2F;Homebrew.sh)&quot;  2、使用Homebrew安装命令 1brew install redis   执">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/Lummer-Li/image-bucket/image/20210302113743.png">
<meta property="article:published_time" content="2021-03-02T03:22:33.099Z">
<meta property="article:modified_time" content="2021-09-20T10:12:02.863Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/Lummer-Li/image-bucket/image/20210302113743.png">
  
    <link rel="alternate" href="/hexo/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/hexo/css/style.css">

<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/hexo/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/hexo/">Home</a>
        
          <a class="main-nav-link" href="/hexo/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/hexo/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://lummer.gitee.io/hexo"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-Mac安装Redis，原来就是这么简单" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/hexo/2021/03/02/Mac%E5%AE%89%E8%A3%85Redis%EF%BC%8C%E5%8E%9F%E6%9D%A5%E5%B0%B1%E6%98%AF%E8%BF%99%E4%B9%88%E7%AE%80%E5%8D%95/" class="article-date">
  <time datetime="2021-03-02T03:22:33.099Z" itemprop="datePublished">2021-03-02</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      使用Homebrew安装Redis
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="使用Homebrew安装Redis"><a href="#使用Homebrew安装Redis" class="headerlink" title="使用Homebrew安装Redis"></a>使用Homebrew安装Redis</h3><p>1、没有安装Homebrew，首先安装npm国内的吧，快一些。</p>
<p>打开终端输入以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/bin/zsh -c &quot;$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)&quot;</span><br></pre></td></tr></table></figure>

<p>2、使用Homebrew安装命令</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">brew install redis</span><br></pre></td></tr></table></figure>


<p>执行上述命令后出现以下，则成功安装：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">==&gt; Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/redis-6.0.1</span><br><span class="line"><span class="meta">#</span><span class="bash"><span class="comment">####################################################################### 100.0%</span></span></span><br><span class="line">==&gt; Pouring redis-6.0.1.mojave.bottle.tar.gz</span><br><span class="line">==&gt; Caveats</span><br><span class="line">To have launchd start redis now and restart at login:</span><br><span class="line">  brew services start redis</span><br><span class="line">Or, if you don&#x27;t want/need a background service you can just run:</span><br><span class="line">  redis-server /usr/local/etc/redis.conf</span><br><span class="line">==&gt; Summary</span><br><span class="line">🍺  /usr/local/Cellar/redis/6.0.1: 13 files, 3.7MB</span><br></pre></td></tr></table></figure>

<p>3、 查看安装及配置文件位置</p>
<ul>
<li><p>Homebrew安装的软件会默认在<code>/usr/local/Cellar/</code>路径下</p>
</li>
<li><p>redis的配置文件redis.conf存放在<code>/usr/local/etc</code>路径下</p>
</li>
</ul>
<p>4、启动redis服务</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">// 方式一：使用brew帮助我们启动软件</span><br><span class="line">brew services start redis</span><br><span class="line">// 方式二</span><br><span class="line">redis-server /usr/local/etc/redis.conf1</span><br><span class="line">// 运行redis, 执行以下命令</span><br><span class="line">redis-server</span><br></pre></td></tr></table></figure>

<p><img src="https://cdn.jsdelivr.net/gh/Lummer-Li/image-bucket/image/20210302113743.png" alt="img"></p>
<p>5、查看redis服务进程</p>
<p>我们可以通过下面命令查看redis是否正在运行</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps axu | grep redis</span><br></pre></td></tr></table></figure>

<p>6、redis-cli连接redis服务</p>
<p>redis默认端口号<strong>6379</strong>，默认<strong>auth</strong>为空，输入以下命令即可连接</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">redis-cli -h 127.0.0.1 -p 6379</span><br></pre></td></tr></table></figure>

<p>7、启动 redis 客户端，打开终端并输入命令 <strong>redis-cli</strong>。该命令会连接本地的 redis 服务。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash">redis-cli</span></span><br><span class="line">redis 127.0.0.1:6379&gt;</span><br><span class="line">redis 127.0.0.1:6379&gt; PING</span><br><span class="line">PONG</span><br></pre></td></tr></table></figure>

<p><code>在以上实例中我们连接到本地的 redis 服务并执行 PING 命令，该命令用于检测 redis 服务是否启动。</code></p>
<p>8、关闭redis服务</p>
<ul>
<li>正确停止Redis的方式应该是向Redis发送<strong>SHUTDOWN</strong>命令</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">redis-cli shutdown</span><br></pre></td></tr></table></figure>

<ul>
<li>强行终止redis</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo pkill redis-server</span><br></pre></td></tr></table></figure>

<p>9、redis.conf 配置文件详解</p>
<p>redis默认是前台启动，如果我们想以守护进程的方式运行（后台运行），可以在<strong>redis.conf</strong>中将<code>daemonize no</code>,修改成<code>yes</code>即可。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="https://lummer.gitee.io/hexo/2021/03/02/Mac%E5%AE%89%E8%A3%85Redis%EF%BC%8C%E5%8E%9F%E6%9D%A5%E5%B0%B1%E6%98%AF%E8%BF%99%E4%B9%88%E7%AE%80%E5%8D%95/" data-id="cktshq5a30004du9l3on73ztb" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/hexo/2021/03/03/Linux/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Linux
        
      </div>
    </a>
  
  
    <a href="/hexo/2021/02/25/Linux%20%E5%AE%89%E8%A3%85%20Nginx/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Linux 安装 Nginx</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/09/">September 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/08/">August 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/07/">July 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/03/">March 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/02/">February 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/01/">January 2021</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/hexo/2021/09/15/hello-world/">Hello World</a>
          </li>
        
          <li>
            <a href="/hexo/2021/08/20/Mac%20%E5%85%A8%E5%B1%8F%E6%97%B6%E8%87%AA%E5%8A%A8%E9%9A%90%E8%97%8F%E7%A8%8B%E5%BA%8F%E5%9D%9E/">Mac 全屏时自动隐藏程序坞</a>
          </li>
        
          <li>
            <a href="/hexo/2021/07/29/Mac%E7%B3%BB%E7%BB%9F%E4%B8%AD%E7%9A%84.DS_Store/">Mac系统中的.DS_Store</a>
          </li>
        
          <li>
            <a href="/hexo/2021/07/21/Markdown/">Markdown</a>
          </li>
        
          <li>
            <a href="/hexo/2021/07/11/Github%E5%9B%BD%E5%86%85%E9%95%9C%E5%83%8F%E7%BD%91%E7%AB%99%EF%BC%8C%E8%A7%A3%E5%86%B3Github%E8%AE%BF%E9%97%AE%E7%9A%84%E7%A5%9E%E5%99%A8/">Github国内镜像网站，解决Github访问的神器</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2021 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/hexo/" class="mobile-nav-link">Home</a>
  
    <a href="/hexo/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/hexo/fancybox/jquery.fancybox.css">

  
<script src="/hexo/fancybox/jquery.fancybox.pack.js"></script>




<script src="/hexo/js/script.js"></script>




  </div>
</body>
</html>